package com.shanzhu.beadhouse.controller;

import com.shanzhu.beadhouse.entity.base.Result;
import com.shanzhu.beadhouse.entity.query.*;
import com.shanzhu.beadhouse.service.NurseGradeService;
import com.shanzhu.beadhouse.service.ServiceProjectService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.http.ResponseEntity;

import java.math.BigDecimal;
import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;

class NurseGradeControllerTest {

    @InjectMocks
    private NurseGradeController nurseGradeController;

    @Mock
    private NurseGradeService nurseGradeService;

    @Mock
    private ServiceProjectService serviceProjectService;

    @BeforeEach
    void setUp() {
        MockitoAnnotations.openMocks(this);
    }

    @Test
    void testPageNurseGradeByKey() {
        // Arrange
        PageNurseGradeByKeyQuery query = new PageNurseGradeByKeyQuery();
        query.setPageNum(0);
        query.setPageSize(10);

        Result mockResult = new Result();
        when(nurseGradeService.pageNurseGradeByKey(query)).thenReturn(mockResult);

        // Act
        Result result = nurseGradeController.pageNurseGradeByKey(query, "mockToken");

        // Assert
        assertEquals(mockResult, result);
        verify(nurseGradeService, times(1)).pageNurseGradeByKey(query);
    }

    @Test
    void testListServiceType() {
        // Arrange
        Result mockResult = new Result();
        when(serviceProjectService.listServiceType(any())).thenReturn(mockResult);

        // Act
        Result result = nurseGradeController.listServiceType("mockToken");

        // Assert
        assertEquals(mockResult, result);
        verify(serviceProjectService, times(1)).listServiceType(null);
    }

    @Test
    void testPageServiceByKey() {
        // Arrange
        PageServiceByKeyQuery query = new PageServiceByKeyQuery();
        query.setPageNum(0);
        query.setPageSize(10);
        Result mockResult = new Result();
        when(nurseGradeService.pageServiceByKey(query)).thenReturn(mockResult);

        // Act
        Result result = nurseGradeController.pageServiceByKey(query, "mockToken");

        // Assert
        assertEquals(mockResult, result);
        verify(nurseGradeService, times(1)).pageServiceByKey(query);
    }

    @Test
    void testAddNurseGrade() {
        // Arrange
        OperateNurseGradeQuery query = new OperateNurseGradeQuery();
        query.setId(112L);
        query.setName("测试等级");
        query.setType("自护");
        query.setMonthPrice(new BigDecimal(10));
        query.setServiceIdList(new ArrayList<>());
        Result mockResult = new Result();
        when(nurseGradeService.addNurseGrade(query)).thenReturn(mockResult);

        // Act
        Result result = nurseGradeController.addNurseGrade(query, "mockToken");

        // Assert
        assertEquals(mockResult, result);
        verify(nurseGradeService, times(1)).addNurseGrade(query);
    }

    @Test
    void testGetNurseGradeById() {
        // Arrange
        Long id = 1L;
        Result mockResult = new Result();
        when(nurseGradeService.getNurseGradeById(id)).thenReturn(mockResult);

        // Act
        Result result = nurseGradeController.getNurseGradeById(id, "mockToken");

        // Assert
        assertEquals(mockResult, result);
        verify(nurseGradeService, times(1)).getNurseGradeById(id);
    }

    @Test
    void testEditNurseGrade() {
        // Arrange
        OperateNurseGradeQuery query = new OperateNurseGradeQuery();
        query.setId(112L);
        query.setName("测试等级");
        query.setType("自护");
        query.setMonthPrice(new BigDecimal(10));
        query.setServiceIdList(new ArrayList<>());
        Result mockResult = new Result();
        when(nurseGradeService.editNurseGrade(query)).thenReturn(mockResult);

        // Act
        Result result = nurseGradeController.editNurseGrade(query, "mockToken");

        // Assert
        assertEquals(mockResult, result);
        verify(nurseGradeService, times(1)).editNurseGrade(query);
    }

    @Test
    void testDeleteNurseGrade() {
        // Arrange
        Long id = 1L;
        Result mockResult = new Result();
        when(nurseGradeService.deleteNurseGrade(id)).thenReturn(mockResult);

        // Act
        Result result = nurseGradeController.deleteNurseGrade(id, "mockToken");

        // Assert
        assertEquals(mockResult, result);
        verify(nurseGradeService, times(1)).deleteNurseGrade(id);
    }
}
